#include <iostream>
#include <string>

using namespace std;

struct Hero {
    string name;
    int age;
    string sex;
};

void bubbleSort(struct Hero heros[], int len) {
    for (int i = 0; i < len - 1; i++) {
        for (int j = 0; j < len - i - 1; j++) {
            if (heros[j].age > heros[j + 1].age) {
                Hero temp = heros[j];
                heros[j] = heros[j + 1];
                heros[j + 1] = temp;
            }
        }
    }
}

void printHeros(struct Hero heros[], int len) {
    for (int i = 0; i < len; i++) {
        cout << heros[i].name << " " << heros[i].age << " " << heros[i].sex << endl;
    }
}

int main() {
    struct Hero heros[5] = {
        {"刘备", 23, "男"},
        {"关羽", 22, "男"},
        {"张飞", 21, "女"},
        {"赵云", 20, "男"},
        {"诸葛亮", 19, "男"}
    };

    int len = sizeof(heros) / sizeof(heros[0]);
    cout << "排序前：" << endl;
    printHeros(heros, len);

    // 冒泡排序
    bubbleSort(heros, len);
    cout << "排序后：" << endl;
    printHeros(heros, len);

    return 0;
}